home *** CD-ROM | disk | FTP | other *** search
- -- card: 46070 from stack: in.3r
- -- bmap block id: 0
- -- flags: 0000
- -- background id: 2202
- -- name: CheckString
-
-
- -- part contents for background part 10
- ----- text -----
- 16
-
- -- part contents for background part 19
- ----- text -----
- Functions
-
- -- part contents for background part 3
- ----- text -----
- CheckString
-
- -- part contents for background part 2
- ----- text -----
- --This function checks a string to make sure it is a valid number.
- --Useful for validating entry fields that are supposed to contain numbers only.
- --From:
- --Peter Sylvan
- --65 Valley Road
- --Milton, MA 02186
- --
- --I would like to thank Peter for sending in this contribution to the Developer Stack. [Steve].
-
-
- function CheckString entry
- -- function to check if argument is a valid number
- -- returns the number of digits if a number, returns empty if not
- put 0 into Ndp -- number of decimal points in entry (0 or 1 is OK)
- repeat with n = 1 to length of entry
- put char n of entry into ch
- if ch is "." then
- add 1 to Ndp
- if Ndp is 2 then
- return empty
- exit CheckString
- end if
- next repeat
- end if
- -- the offset function is used here to check each character in the
- -- input against a list of valid characters ("1234567890")
- if offset(ch,"1234567890") is "0" then -- ch is not a digit
- return empty
- exit CheckString
- end if
- end repeat
- return length of entry - Ndp
- end CheckString